/**
 * Created by Administrator on 2016/1/20.
 */
    var pageall;  /*总页数*/
    var pagenow;  /*当前页*/
    var se=decodeURIComponent(window.location.search).substring(1);
    var msg=se.split("&")[0];



$(function(){
      getInfo();
    });

$(".classify_t").click(function(){
//    alert($(this).children().text())
//    getInfo(obj,key);
})

//分页组件
function creatpage(total,now){
    $(".tcdPageCode").createPage({
        pageCount:total,
        current:now,
        backFn:function(p){
            getInfo(p);
//            alert(p)
        }
    })
}



//查询分页
function getInfo(obj){
    //判断跳转方式
    if(msg==""){
//        alert("查询全部消息")
        //         查询全部数据分页
        if(typeof(obj)=="undefined"){
        	alert("1")
            var a=1;
            var size = 9;
            $.ajax({
                type:"POST",
                url:_MVC_BASEPATH+"/PostHadle/postQuerForPage",
                dataType:"json",
                data:'param='+'{size:'+size+',currentpage:'+a+'}',
                success:function(result){
                    if(result.code=="1"){
                    	alert("2")
                        $(".classify_box").html("");
                        $(".classify_box").append(
                                "<div id='content_box'></div>"+
                                "<div class='tcdPageCode'></div>"
                        )
                        var re=result.content;
                        $("#content_box").html("");
                        for(var i in re.dataInfo) {
                            $("#content_box").append(
                                    "<div class='box'>"+
                                    "<div class='img bor'><img src='"+re.dataInfo[i].firstImageUrl+"' alt='供应产品' width='100%'></div>"+
                                    "<div class='txt'>"+
                                    "<h3><a href='"+re.dataInfo[i].postUrl+"'>"+re.dataInfo[i].postTitle+"</a></h3>"+
                                    "<p>"+re.dataInfo[i].postContent+"</p>"+
                                    "<div class='sjxx'>"+
                                    "<div class='sjxx_gs'><span>["+re.dataInfo[i].province+"]</span>"+re.dataInfo[i].userName+"</div>"+
                                    "<div class='sjxx_sj'>"+re.dataInfo[i].addTime+"</div>"+
                                    "</div>"+
                                    " </div>"+
                                    "<div class='bu2 white' onclick='window.location.href='"+re.dataInfo[i].postUrl+"''>了解更多"+
                                    "</div>"+
                                    "</div>"
                            )
                        }
                        pagenow=1;
                        pageall=re.totalCount;
                        creatpage(pageall,pagenow);/*调用分页组件*/

                    }else{
                    	alert("3")
                        $(".classify_box").html("");
                        $(".classify_box").append(
                            "<div class='hint fw_b'>抱歉，没有找到相关的内容。</div>"
                        )
                    }
                },
                error: function() {
                }
            });
        }else{
            var a=obj;
            var size = 9;
            $.ajax({
                type:"POST",
                url:_MVC_BASEPATH+"/PostHadle/postQuerForPage",
                dataType:"json",
                data:'param='+'{size:'+size+',currentpage:'+a+'}',
                success:function(result){
                    if(result.code=="1"){
                        $(".classify_box").html("");
                        $(".classify_box").append(
                                "<div id='content_box'></div>"+
                                "<div class='tcdPageCode'></div>"
                        )
                        var re=result.content;
                        $("#content_box").html("");
                        for(var i in re.dataInfo) {
                            $("#content_box").append(
                                    "<div class='box'>"+
                                    "<div class='img bor'><img src='"+re.dataInfo[i].firstImageUrl+"' alt='供应产品' width='100%'></div>"+
                                    "<div class='txt'>"+
                                    "<h3><a href='"+re.dataInfo[i].postUrl+"'>"+re.dataInfo[i].postTitle+"</a></h3>"+
                                    "<p>"+re.dataInfo[i].postContent+"</p>"+
                                    "<div class='sjxx'>"+
                                    "<div class='sjxx_gs'><span>["+re.dataInfo[i].province+"]</span>"+re.dataInfo[i].userName+"</div>"+
                                    "<div class='sjxx_sj'>"+re.dataInfo[i].addTime+"</div>"+
                                    "</div>"+
                                    " </div>"+
                                    "<div class='bu2 white' onclick='window.location.href='"+re.dataInfo[i].postUrl+"''>了解更多"+
                                    "</div>"+
                                    "</div>"
                            )
                        }
                        pagenow=obj;
                        pageall=re.totalCount;
                        creatpage(pageall,pagenow);/*调用分页组件*/

                    }else{
                        $(".classify_box").html("");
                        $(".classify_box").append(
                            "<div class='hint fw_b'>抱歉，没有找到相关的内容。</div>"
                        )
                    }
                },
                error: function() {
                }
            });
        }
    }else{
        alert("查询"+msg)
        if(typeof(obj)=="undefined"){
            var a=1;
            var size = 9;
            $.ajax({
                type:"POST",
                url:_MVC_BASEPATH+"/FuzzyQuerHandle/FuzzyQuer",
                dataType:"json",
                data:{param:msg,size:size,currentpage:a,type:2},
                success:function(result){
                    if(result.code=="1"){
                        $(".classify_box").html("");
                        $(".classify_box").append(
                                "<div id='content_box'></div>"+
                                "<div class='tcdPageCode'></div>"
                        )
                        var re=result.content;
                        $("#content_box").html("");
                        for(var i in re.dataInfo) {
                            $("#content_box").append(
                                    "<div class='box'>"+
                                    "<div class='img bor'><img src='"+re.dataInfo[i].firstImageUrl+"' alt='供应产品' width='100%'></div>"+
                                    "<div class='txt'>"+
                                    "<h3><a href='"+re.dataInfo[i].postUrl+"'>"+re.dataInfo[i].postTitle+"</a></h3>"+
                                    "<p>"+re.dataInfo[i].postContent+"</p>"+
                                    "<div class='sjxx'>"+
                                    "<div class='sjxx_gs'><span>["+re.dataInfo[i].province+"]</span>"+re.dataInfo[i].userName+"</div>"+
                                    "<div class='sjxx_sj'>"+re.dataInfo[i].addTime+"</div>"+
                                    "</div>"+
                                    " </div>"+
                                    "<div class='bu2 white' onclick='window.location.href='"+re.dataInfo[i].postUrl+"''>了解更多"+
                                    "</div>"+
                                    "</div>"
                            )
                        }
                        pagenow=1;
                        pageall=re.totalCount;
                        creatpage(pageall,pagenow);/*调用分页组件*/

                    }else{
                        $(".classify_box").html("");
                        $(".classify_box").append(
                        		"<div class='hint fw_b'>抱歉，没有找到与'<span class='red'>"+msg+"</span>'相关的内容。</div>"
                        )
                    }
                },
                error: function() {
                }
            });
        }else{
            var a=obj;
            var size = 9;
            $.ajax({
                type:"POST",
                url:_MVC_BASEPATH+"/PostHadle/postQuerForPage",
                dataType:"json",
                data:'param='+'{size:'+size+',currentpage:'+a+'}',
                success:function(result){
                    if(result.code=="1"){
                        $(".classify_box").html("");
                        $(".classify_box").append(
                                "<div id='content_box'></div>"+
                                "<div class='tcdPageCode'></div>"
                        )
                        var re=result.content;
                        $("#content_box").html("");
                        for(var i in re.dataInfo) {
                            $("#content_box").append(
                                    "<div class='box'>"+
                                    "<div class='img bor'><img src='"+re.dataInfo[i].firstImageUrl+"' alt='供应产品' width='100%'></div>"+
                                    "<div class='txt'>"+
                                    "<h3><a href='"+re.dataInfo[i].postUrl+"'>"+re.dataInfo[i].postTitle+"</a></h3>"+
                                    "<p>"+re.dataInfo[i].postContent+"</p>"+
                                    "<div class='sjxx'>"+
                                    "<div class='sjxx_gs'><span>["+re.dataInfo[i].province+"]</span>"+re.dataInfo[i].userName+"</div>"+
                                    "<div class='sjxx_sj'>"+re.dataInfo[i].addTime+"</div>"+
                                    "</div>"+
                                    " </div>"+
                                    "<div class='bu2 white' onclick='window.location.href='"+re.dataInfo[i].postUrl+"''>了解更多"+
                                    "</div>"+
                                    "</div>"
                            )
                        }
                        pagenow=obj;
                        pageall=re.totalCount;
                        creatpage(pageall,pagenow);/*调用分页组件*/

                    }else{
                    	alert("22222")
                        $(".classify_box").html("");
                        $(".classify_box").append(
                            "<div class='hint fw_b'>抱歉，没有找到与'<span class='red'>"+msg+"</span>'相关的内容。</div>"
                        )
                    }
                },
                error: function() {
                }
            });
        }
    }
}


